﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TV4Home.Server.TVEInteractionLibrary.Interfaces;

namespace TV4Home.Server.Vail.AddIn
{
    public partial class SelectTVChannelGroupForm : Form
    {
        public SelectTVChannelGroupForm()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void PopulateGroups(List<WebChannelGroup> groups, int preSelectedChannelGroupId)
        {
            // add all groups
            foreach (WebChannelGroup group in groups)
            {
                int index = this.cmbGroups.Items.Add(new KeyValuePair<int, string>(group.IdGroup, group.GroupName));

                if (group.IdGroup == preSelectedChannelGroupId)
                    this.cmbGroups.SelectedIndex = index;
            }
        }

        public int SelectedGroupId
        {
            get
            {
                if (this.cmbGroups.SelectedItem != null)
                    return ((KeyValuePair<int, string>)this.cmbGroups.SelectedItem).Key;

                return 0;
            }
        }

        private class KeyValuePair<K, V>
        {
            public K Key;
            public V Value;

            public KeyValuePair(K key, V value)
            {
                Key = key;
                Value = value;
            }

            public override string ToString()
            {
                return Value.ToString();
            }
        }
    }
}
